package StreamDemo;

import java.util.stream.Stream;

/**
 * @Author: ylc
 * @Description: Stream<T> filter(Predicate<? super T> predicate);
 * @Date Created in 2022-05-05 19:59
 */
public class demo3_filter {
    public static void main(String[] args) {
        Stream<String> stream1 = Stream.of("叶良承", "张三", "赵云", "张飞");
        Stream<String> stream2 = stream1.filter(name -> name.startsWith("张"));
        //遍历stream1流
        stream2.forEach(name -> System.out.println(name));
        /*
            Stream流属于管道流,只能被消费(使用)一次
            第一个Stream流调用完毕方法,数据就会流转到下一个Stream上
            这时Stream1流已经使用完毕,就会关闭了
            所以Stream1流就不能再调用方法了
                IllegalStateException: stream has already been operated upon or closed
         */
        stream1.forEach(name -> System.out.println(name));
    }
}
